const indexModel = require("../models/index_model")

const Result = require("../beans/result")

// 以下代码可封装
function doGetAllIndexInfo(callback) {
    indexModel.getAllIndexInfo((err, data) => {
        if (err) {
            callback(new Result(err, null, "查询数据失败", 401))
        } else {

            callback(new Result(null, data, "查询数据成功", 200))
        }
    })
}

function doGetgoodsDetail(callback) {
    indexModel.getDetails((err, data) => {
        if (err) {
            callback(new Result(err, null, "查询商品详情数据失败", 401))
        } else {

            callback(new Result(null, data, "查询商品详情数据成功", 200))
        }
    })
}


// 轮播图
function AddRotationlist(Rotation, callback) {
    indexModel.createRotation(Rotation, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加轮播图失败", 401))
        } else {
            callback(new Result(null, data, "添加轮播图成功", 200))
        }
    })
}

function putRotationlist(Rotation, callback) {
    indexModel.updateRotation(Rotation, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改轮播图失败", 401))
        } else {
            callback(new Result(null, data, "修改轮播图成功", 200))
        }
    })
}

function deleteRotationlist(RotationId, callback) {
    indexModel.deleteRotation(RotationId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除轮播图失败", 401))
        } else {
            callback(new Result(null, data, "删除轮播图成功", 200))
        }
    })
}


function AddGoodslist(goods, callback) {
    indexModel.addgoods(goods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加热卖商品失败", 401))
        } else {
            callback(new Result(null, data, "添加热卖商品成功", 200))
        }
    })
}

function putGoodslist(putgoods, callback) {
    indexModel.updatehotgoods(putgoods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改热卖商品失败", 401))
        } else {
            callback(new Result(null, data, "修改热卖商品成功", 200))
        }
    })
}


function deletegoodslist(goodsId, callback) {
    indexModel.deletehotgoods(goodsId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除热卖商品失败", 401))
        } else {
            callback(new Result(null, data, "删除热卖商品成功", 200))
        }
    })
}


function AddNewGoodslist(newgoods, callback) {
    indexModel.addNewgoods(newgoods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加新商品失败", 401))
        } else {
            callback(new Result(null, data, "添加新商品成功", 200))
        }
    })
}

function putnewGoodslist(putnewgoods, callback) {
    indexModel.updatenewgoods(putnewgoods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改新商品失败", 401))
        } else {
            callback(new Result(null, data, "修改新商品成功", 200))
        }
    })
}

function deletenewgoodslist(newgoodsId, callback) {
    indexModel.deletenewgoods(newgoodsId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除新商品失败", 401))
        } else {
            callback(new Result(null, data, "删除新商品成功", 200))
        }
    })
}

function AddRemGoodslist(remgoods, callback) {
    indexModel.addRemgoods(remgoods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "添加新商品失败", 401))
        } else {
            callback(new Result(null, data, "添加新商品成功", 200))
        }
    })
}
function putRemGoodslist(putRemgoods, callback) {
    indexModel.updateremgoods(putRemgoods, (err, data) => {
        if (err) {
            callback(new Result(err, null, "修改新商品失败", 401))
        } else {
            callback(new Result(null, data, "修改新商品成功", 200))
        }
    })
}


function deleteRemgoodslist(remgoodsId, callback) {
    indexModel.deleteRemgoods(remgoodsId, (err, data) => {
        if (err) {
            callback(new Result(err, null, "删除新商品失败", 401))
        } else {
            callback(new Result(null, data, "删除新商品成功", 200))
        }
    })
}
module.exports = {
    doGetAllIndexInfo,
    doGetgoodsDetail,
    AddRotationlist,
    putRotationlist,
    deleteRotationlist,
    AddGoodslist,
    putGoodslist,
    deletegoodslist,
    AddNewGoodslist,
    putnewGoodslist,
    deletenewgoodslist,
    AddRemGoodslist,
    putRemGoodslist,
    deleteRemgoodslist
    
}